﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using D6.DFS.Consumer;

namespace Streaming_Services_WPF_Consumer
{
    public class DfsWrapper : DfsConsumer
    {
        protected String mmsUrl = null;
        protected String r_object_id = null;

        public enum QueryType
        {
            Get_R_Object_ID,
            Get_MMS_URL,
        }

        protected QueryType m_queryType;


        public DfsWrapper(String repository, String username, String password)
            : base(repository, username, password)
        {

        }

        protected override void processQueryResults(D6.DFS.Consumer.QueryService.QueryResult repositoryItems)
        {
            if (m_queryType == QueryType.Get_MMS_URL)
            {
                foreach (D6.DFS.Consumer.QueryService.DataObject attr in repositoryItems.dataPackage.DataObjects)
                {
                    D6.DFS.Consumer.QueryService.PropertySet attrPropertySet = attr.Properties;
                    D6.DFS.Consumer.QueryService.Property property = attrPropertySet.Properties[0];
                    D6.DFS.Consumer.QueryService.StringArrayProperty strArrayProperty = (D6.DFS.Consumer.QueryService.StringArrayProperty)property;
                    mmsUrl = strArrayProperty.Values[0];
                }
            }
            else if (m_queryType == QueryType.Get_R_Object_ID)
            {
                foreach (D6.DFS.Consumer.QueryService.DataObject attr in repositoryItems.dataPackage.DataObjects)
                {
                    D6.DFS.Consumer.QueryService.PropertySet attrPropertySet = attr.Properties;
                    D6.DFS.Consumer.QueryService.Property property = attrPropertySet.Properties[0];
                    D6.DFS.Consumer.QueryService.StringProperty strProperty = (D6.DFS.Consumer.QueryService.StringProperty)property;
                    r_object_id = strProperty.Value;
                }
            }

        }

        public String WMS_URL
        {
            get
            {
                return mmsUrl;
            }
        }

        public String Object_ID
        {
            get
            {
                return r_object_id;
            }
        }

        public QueryType DQL_To_Execute
        {
            get
            {
                return m_queryType;
            }
            set
            {
                m_queryType = value;
            }
        }


    }
}
